package com.zsxb.crm.mapper;


import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.github.pagehelper.Page;
import com.zsxb.crm.annotation.AutoFill;
import com.zsxb.crm.annotation.Log;
import com.zsxb.crm.dto.AddUserDTO;
import com.zsxb.crm.enumeration.OperationType;
import com.zsxb.crm.dto.UserPageDTO;
import com.zsxb.crm.enumeration.OperationType;
import com.zsxb.crm.pojo.User;
import com.zsxb.crm.vo.UserDeptVO;

import com.zsxb.crm.vo.UserListSelectVO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;

@Mapper
public interface UserMapper extends BaseMapper<User> {
    //分页查询
    Page<User> pageUser(UserPageDTO pageDTO);

    //新增用户

    @AutoFill(OperationType.INSERT)
    void addUser(@Param("addUserDTO") AddUserDTO addUserDTO, @Param("strRoleIds") String strRoleIds);

    //修改用户

    void updataUser(User user);

    //根据用户名查询用户
    @Select("select * from user where username = #{username}")
    User findByUserName(String username);

    //根据id查询用户
    User getById(Long id);


    //批量删除用户
    void delByIds(String[] ids);

    //用户列表查询根据部门ID
    List<UserListSelectVO> listselect(Integer deptId);

    //同步更新id
    @AutoFill(OperationType.UPDATE)
    void updateId(Long id);

    @Select("select count(1) from user where update_time_time between #{startOfDay} and #{endOfDay}")
    Integer queryNewUserByDate(LocalDateTime startOfDay, LocalDateTime endOfDay);
    @Select("select count(1) from user")
    Integer queryAll();


    @Update("update report_statistics set new_user = #{newUser}, total_user = #{totalUser} where date = #{yesterday}")
    void addUserDataByDate(LocalDate yesterday, Integer newUser, Integer totalUser);
    //根据部门ID查询用户
    UserDeptVO getUser(Integer deptId);

    @Select("select username from user where user_id=#{userId}")
    String findUserNameById(Long userId);
    List<UserListSelectVO> listselect(Long deptId);

    //@Select("select * from user")
    //List<User> queryAll();


}
